package cn.edu.hqu.tkserver.modules.tk.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.hqu.tkserver.common.utils.PageUtils;
import cn.edu.hqu.tkserver.common.utils.Query;
import cn.edu.hqu.tkserver.common.utils.R;
import cn.edu.hqu.tkserver.modules.tk.entity.TicketEntity;
import cn.edu.hqu.tkserver.modules.tk.service.TicketService;


/**
 * 车票
 */
@RestController
@RequestMapping("ticket")
public class TicketController {
	@Autowired
	private TicketService ticketService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("ticket:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TicketEntity> ticketList = ticketService.queryList(query);
		int total = ticketService.queryTotal(query);
		
		return R.ok().put("rows", ticketList).put("total", total);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("ticket:info")
	public R info(@PathVariable("id") Integer id){
		TicketEntity ticket = ticketService.queryObject(id);
		
		return R.ok().put("ticket", ticket);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("ticket:save")
	public R save(@RequestBody TicketEntity ticket){
		ticket.setCreateTime(new Date());
		ticketService.save(ticket);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("ticket:update")
	public R update(@RequestBody TicketEntity ticket){
		ticketService.update(ticket);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("ticket:delete")
	public R delete(@RequestBody Integer[] ids){
		ticketService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
